import request from '../../utils/request';
const banner = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    // banner 状态 state: normal('正常') expired('失效') deleted（删除）
    /**
     * 获取banner列表
     * @payload{
     *  title   string 
     *  type   string  pc("pc端"), app("app端"), example("案例"), video("短剧"),about("关于我们"), expert("专家");
     * 
     * }
     * */ 
    GET_BANNER_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.get('/banner/list.htm', {
          params: payload
        }).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * banner管理-新建/更新
     * @payload{
     *  id      string 为null新建，否则修改
     *  title   string 
     *  desc    string
     *  link    string 
     *  pic     string
     *  type    string  pc("pc端"), app("app端"), example("案例"), video("短剧"),about("关于我们"), expert("专家");
     *  state   string  normal 正常，deleted删除  expired("已失效"),
     * }
     * */ 
    UPDATE_BANNER({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/banner/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * banner管理-详情
     * @payload{
     *  id      string 
     * }
     * */ 
    GET_BANNER_DETAIL({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/banner/detail.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    }

  }
}

export default banner